auto.waitFor()
var appRun = currentActivity()
var t = 0

let taskList = ["应用商店", "i视频", "游戏中心", "i音乐", "i主题", "钱包", "快应用"]
/**
 * 上滑
 */
function swipe_my() {

    // random_time = getRndInteger(500,1500)

    // swipe(500, 1800, 500, 800, random(200,1500))

    swipe(500, 1800, 500, 1300, random(200, 1500))

    // gesture(1000, [600, 1600], [500, 1000])

}

/**
 * 左滑
 */
function swipe_left_to_visible(btn) {
    var position = btn.bounds();
    position.centerX()

    toastLog(position.centerX() - 1000)

    // random_time = getRndInteger(500,1500)

    // swipe(500, 1800, 500, 800, random(200,1500))
    let times = (position.centerX() - 1000) / 300
    for (let t = 0; t < times; t++) {
        swipe(500, position.centerY(), 200, position.centerY(), random(200, 500))
    }

    // gesture(1000, [600, 1600], [500, 1000])

}
/**
 * 
 * 通过bounds 点击
 * @param {*} btn  按钮对象
 */
function clickBtnByBoundsCenter(btn) {
    var position = btn.bounds();
    press(position.centerX(), position.centerY(), 1);
    sleep(1000);
}

/**
 * 是否可见的按钮
 * @param {} btn 
 */
function isVisiableBtn(btn) {
    let btn = text(taskList[4]).findOne(1000)
    if (btn.centerX > 1100) {
        return false;
    }
}

/**
 * 进入 主页面
 */
function enterMain() {
    app.openUrl("https://pointh5.vivo.com.cn/#/taskList")
    sleep(2000)
    swipe_my()

}


/**
 * 清除后台
 */
function clearBackApp() {
    home()
    sleep(1000)

    recents()

    sleep(2000)

    let cleanBackBtn = desc("清除全部-按钮").findOne(2000)
    clickBtnByBoundsCenter(cleanBackBtn)
}


let myBtn = text("去完成").findOne(2000)

while (isVisiableBtn(myBtn)) {
    swipe_my()
    clickBtnByBoundsCenter(myBtn)

}

